<script>
    import Vue from 'vue'
    import Voice from './nddyny/js/QS-baiduyy.js'
    export default {
        onLaunch: function() {
            uni.getSystemInfo({
                success: (e) => {
                    // #ifndef MP
                    Vue.prototype.status_bar = e.statusBarHeight;
                    // #ifdef H5
                    Vue.prototype.custom_bar = e.statusBarHeight + 45;
                    // #endif
                    // #ifndef H5
                    if (e.platform == 'android') {
                        Vue.prototype.custom_bar = e.statusBarHeight + 50;
                    } else {
                        Vue.prototype.custom_bar = e.statusBarHeight + 45;
                    };
                    // #endif
                    // #endif
                    // #ifdef MP-WEIXIN
                    Vue.prototype.status_bar = e.statusBarHeight;
                    let custom = wx.getMenuButtonBoundingClientRect();
                    Vue.prototype.Custom = custom;
                    Vue.prototype.custom_bar = custom.bottom + custom.top - e.statusBarHeight;
                    // #endif		
                    // #ifdef MP-ALIPAY
                    Vue.prototype.status_bar = e.statusBarHeight;
                    Vue.prototype.custom_bar = e.statusBarHeight + e.titleBarHeight;
                    // #endif

                    this.$store.state.app.status_bar = Vue.prototype.status_bar + 'px';
                    this.$store.state.app.custom_bar = Vue.prototype.custom_bar + 'px';
                }
            });
            let user_auth_token = uni.getStorageSync('user_auth_token');
            if (user_auth_token) {
                this.$store.commit('setUserLogin', {
                    auth_token: user_auth_token,
                    login_info: {
                        identity_info: uni.getStorageSync('user_identity_info'),
                        user_asset_info: uni.getStorageSync('user_asset_info')
                    }
                });
            }

            setTimeout(() => {
                // #ifdef APP-PLUS
                plus.push.getClientInfoAsync((info) => {
                    // #endif
                    this.$api.post(this, {
                        url: '/alone/appLaunch_v2',
                        data_key: null,
                        data_append: {
                            version_no: this.$app.version_no,
                            // #ifdef APP-PLUS
                            getui_cid: info.clientid,
                            // #endif
                        },
                        success: (Result) => {
                            if (this.$api.form.toast(this, Result)) return;
                            this.article_list = Result.result.article_list || [];
                            let verify_app_upgrade_list = Result.result.verify_app_upgrade_list;
                            let user_info = Result.result.user_info;
                            if (verify_app_upgrade_list.length > 0) {
                                this.$app.upgrade_list = verify_app_upgrade_list
                                this.$store.commit('userLaunchTo', '/page/index');
                            }
                            if (user_info.identity_info) {
                                this.$store.commit('setIdentityInfo', user_info.identity_info);
                            }
                            if (user_info.user_asset_info) {
                                this.$store.commit('setUserAssetInfo', user_info.user_asset_info);
                            }
                        }
                    });
                    // #ifdef APP-PLUS
                }, err => {});
                // #endif
            }, 1500);

            // #ifdef APP-PLUS
            plus.push.addEventListener("click", function(msg) {
                let data = {};
                if (msg.payload.payload) {
                    data = msg.payload.payload;
                } else {
                    data = msg.payload;
                }
                let action_type = data.action_type || '';
                let seller_type = data.seller_type || '';
                let url = '';
                switch (action_type + '') {
                    case '74': // 线下收款到账
                        url = '/pages/seller/facePayList?is_manage=1';
                        break;
                    case '2000': // 商家接到一笔新订单
                        url = '/pages/seller/item/order/list?is_manage=1&seller_type=' + seller_type;
                        break;
                    case '61': // 提现消费红包成功
                        url = '/pages/user/asset/withdraw';
                        break;
                    case '71': // 提现货款成功
                        url = '/pages/user/asset/withdraw';
                        break;
                }
                if (url) {
                    uni.navigateTo({
                        url: url
                    })
                }
            }, false);

            plus.push.addEventListener("receive", function(msg) {
                //转换点击消息通知内的参数
                let messageBox = JSON.parse(msg.content)._tc
                //参数通过“,”分割
                let message1 = messageBox.split(',')
                //提示的消息和播报的内容在第一个通过“；”分割
                let message2 = message1[0].split(';')
                Voice(message2[1]);
                plus.push.createMessage(message2[1], msg);
            }, false);
            // #endif
        },
    }
</script>

<style lang="less">
    /*每个页面公共css */
    @import "colorui/main.css";
    @import "colorui/icon.css";
    @import "nddyny/css/changeColorui.less";
    @import "nddyny/css/common.less";
    @import "nddyny/css/app.less";
    @import "nddyny/css/theme.less";
    @import "nddyny/css/text.less";
    @import "nddyny/css/margin.css";
    @import "nddyny/css/padding.css";
</style>
